package com.justech.eat.global;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.util.Properties;

/**
 * @program: eat-service
 * @description: mybatis拦截器
 * @author: feifei.li
 * @create: 2020-06-01 11:20
 **/
@Component
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class MybatisInterceptor implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {

        System.out.println(invocation);
        return invocation;
    }

    @Override
    public Object plugin(Object target) {
        System.out.println(target);
        return target;
    }

    @Override
    public void setProperties(Properties properties) {
        System.out.println(properties);
    }
}
